<?php

//No direct access

defined('_JEXEC') or die('Restricted access');

?>

<div id="ownservices">


 <div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>


	<div id="mainownservice">

		<h3><?php echo JText::_('OWNSERVICE_TRANSFERRED_RECORD_ALL'); ?></h3>

		<script language="javascript" type="text/javascript">
			<!--
				function submitbutton(pressbutton)
				{
					var form = document.adminForm;

					if(pressbutton == 'delete') {
						if (form.boxchecked.value == 0){
							alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_TRANSACTIONS', true ); ?>" );
							return;
						} 
					}

					submitform( pressbutton );
				}
			//-->
		</script>

		<hr />
		<div id="toolbar">			
			<a class="toolbar" onclick="javascript: submitbutton('download');" href="#">
				<span title="<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>" class="icon-32-export"></span>
				<?php echo JText::_('OWNSERVICE_DOWNLOAD').' '.'IFTI-DRA'; ?>
			</a>

			<a class="toolbar" onclick="submitbutton('delete');" href="#">
				<span title="<?php echo JText::_('OWNSERVICE_DELETE'); ?>" class="icon-32-delete"></span>
				<?php echo JText::_('OWNSERVICE_DELETE'); ?>
			</a>
		</div>
		<div class="clear"> </div>

		<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">



	  <table class="admintable">

		<tr>

			<td class="key" style="width: 80px;"><?php echo JText::_('OWNSERVICE_SELECT_PERIOD'); ?></td>

			<td>

				<strong>

				<?php

					$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 

					if($this->data['period'] == 1) {

						echo JHTML::_('date',$this->data['date'], $dateformat);

					} else if($this->data['period'] == 2) {

						echo JText::_('OWNSERVICE_FROM').' '.JHTML::_('date', (' 01-'.$this->data['month'].'-'.date('Y')), $dateformat).' '.JText::_('OWNSERVICE_TO').' '.JHTML::_('date', (date("t", mktime(0,0,0,$this->data['month'],1,date('Y'))).'-'.$this->data['month'].'-'.date('Y')), $dateformat);

					} else if($this->data['period'] == 3) {

						echo JText::_('OWNSERVICE_FROM').' '.JHTML::_('date', $this->data['from'], $dateformat).' '.JText::_('OWNSERVICE_TO').' '.JHTML::_('date', $this->data['to'], $dateformat);

					}

				?>

				</strong>

			</td>

		</tr>

	  </table>



      <table class="adminlist" cellspacing="1">

        <tr> 
		 <td align="center" class="tablelist">
			<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />	
		 </td>
          <td align="center" class="tablelist">
			<?php /*echo JText::_('OWNSERVICE_RECEIVER_NO');*/ ?>
			<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RECEIVER_NO', 't.invoice', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

          <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_ACCOUNT_NO');*/ ?>
		  <?php echo JHTML::_('grid.sort',  'OWNSERVICE_ACCOUNT_NO', 't.account', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

          <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_USER');*/ ?>
		  <?php echo JHTML::_('grid.sort',  'OWNSERVICE_USER', 'u.username', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

          <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_TRANSFER_ON');*/ ?>
		  <?php echo JHTML::_('grid.sort',  'OWNSERVICE_TRANSFER_ON', 't.requested_date', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

          <?php /*<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_STATUS'); ?></td> */ ?>

          <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_AMOUNT_TRANSFER');*/ ?>
		  <?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  <br />
		  (AUD)
		  </td>

          <td align="center" class="tablelist">
			<?php /*echo JText::_('OWNSERVICE_RATE');*/ ?>
			<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RATE', 't.rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

          <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_TOTAL_EXCHANGE');*/ ?>
		  <?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		  </td>

		  <td align="center" class="tablelist">
		  <?php /*echo JText::_('OWNSERVICE_FEE');*/ ?>
			<?php echo JHTML::_('grid.sort',  'OWNSERVICE_FEE', 't.fee', $this->lists['order_Dir'], $this->lists['order'] ); ?>
			<br />
            (AUD)
		  </td>

        </tr>

        <?php
					$k = 0;
					$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');

					$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 

					$total_amount = 0;

					$total_transfer = 0;

					$total_fee = 0;

					for($i=0,$n=count($this->rows);$i<$n;$i++): 

					$row = $this->rows[$i];
					$checked = JHTML::_('grid.checkedout', $row, $i );

				?>

        <tr class="<?php echo "row$k"; ?>"> 

		<td align="center" class="inner_tablelist">
			<?php echo $checked; ?>
		</td>	
          <td align="center" class="inner_tablelist"> 
          	<a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=transaction&task=detail&id='.$row->id); ?>">
          		<?php echo $row->invoice; ?>
          	</a> 
          </td>

          <td align="center" class="inner_tablelist"><?php echo OwnserviceHelper::accountFormat($row->account); ?></td>

          <td class="inner_tablelist"><a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->proid); ?>"><?php echo $row->username; ?></a></td>

          <td align="center" class="inner_tablelist"><?php echo JHTML::_('date', $row->created, $dateformat); ?></td>

          <?php /*<td align="center" class="inner_tablelist"><?php echo OwnserviceHelper::getStatus($row->id, $row->state); ?></td> */ ?>

          <td class="inner_tablelist" align="center"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?></td>

          <td class="inner_tablelist" align="right">
		  <?php
				$color = '';
				if($row->extrarate > 0.00 ) {
					$color = 'red';
				} else if($row->extrarate < 0.00) {
					$color = 'green';
				}
			?>
			<?php if(!$row->iscore): ?>
			<div style="border-bottom: 1px solid;">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
			</div>
			<?php endif; ?>
			<div>
				<span class ="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?></span>
				<?php echo $row->rate_code; ?> 
			</div>
		  </td>

          <td class="inner_tablelist" align="right">
			<?php
				$color = '';
				$total = 0;
				if($row->extratotal > 0.00 ) {
					$color = 'red';
					$total = $row->extratotal;
				} else {
					$total = $row->amount * ($row->rate+$row->extrarate);
				}
			?>
				<?php if(!$row->iscore): ?>
				<div style="border-bottom: 1px solid;">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
				</div>
				<?php endif; ?>
				<div>
				<span class="<?php echo $color; ?>">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,($total- ($row->bankfee+$row->extrabfee))); ?>
				</span> <?php echo $row->rate_code; ?>
				</div>
		  </td>

		  <td class="inner_tablelist" align="center">
			<?php
				$color = '';
				if($row->extrafee > 0.00) {
					$color = 'red';
				} else if($row->extrafee < 0.00) {
					$color = 'green';
				}
			  ?>
			<span class="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->fee+$row->extrafee); ?></span>
		</td>

        </tr>

        <?php

			$total_amount 	= $total_amount + $row->amount;

			$total_fee		= $total_fee + ($row->fee+$row->extrafee);

			if(!$row->iscore) {
					$total_transfer = $total_transfer + (($row->amount * $row->rate_th));
			} else {
				if($row->extratotal > 0.00 ) {
					$total_transfer = $total_transfer + ($row->extratotal - ($row->bankfee+$row->extrabfee));
				} else {
						$total_transfer = $total_transfer + (($row->amount * ($row->rate+$row->extrarate))- ($row->bankfee+$row->extrabfee));
				}
			}
			$k = 1 - $k; endfor; 
		?>

        <tr> 

          <td colspan="5" align="right"><strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong></td>

          <td align="center"><u><strong><?php echo OwnserviceHelper::moneyFormat($priceformat,$total_amount); ?></u></strong></td>

          <td align="center"></td>

          <td align="right"><strong><u><?php echo OwnserviceHelper::moneyFormat($priceformat,$total_transfer); ?></u> THB</strong></td>

		  <td align="center"><strong><u><?php echo OwnserviceHelper::moneyFormat($priceformat,$total_fee); ?></u></strong></td>

        </tr>
      </table>
			<input type="hidden" name="boxchecked" value="0" />
			<input type="hidden" name="option" value="com_ownservice" />

			<input type="hidden" name="task" value="transferredRecord" />

			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />

			<input type="hidden" name="period" value="<?php echo $this->data['period']; ?>" />

			<input type="hidden" name="date" value="<?php echo $this->data['date']; ?>" />

			<input type="hidden" name="month" value="<?php echo $this->data['month']; ?>" />

			<input type="hidden" name="from" value="<?php echo $this->data['from']; ?>" />

			<input type="hidden" name="to" value="<?php echo $this->data['to']; ?>" />

			<input type="hidden" name="controller" value="report" />

			<input type="hidden" name="view" value="report" />

			<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
			<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
			<?php echo JHTML::_( 'form.token' ); ?>

		</form>

	</div>

</div>